package com.lastproject.web.bean;

import java.io.Serializable;

import javax.ejb.EJB;

import com.lastproject.dto.EmailGroupDTO;
import com.lastproject.ejb.dao.EmailGroupDAORemote;

public class GroupBean implements Serializable {

	/**
	 * 
	 */
	private static final long serialVersionUID = -1503554029580368226L;

	@EJB
	EmailGroupDAORemote emailGroupDAORemote;

	private EmailGroupDTO emailGroupDTO;
	
	private boolean hasPermission = true;
	private String noRights = "";

	public boolean isHasPermission() {
		return hasPermission;
	}

	public void setHasPermission(boolean hasPermission) {
		this.hasPermission = hasPermission;
	}

	public String getNoRights() {
		return noRights;
	}

	public void setNoRights(String noRights) {
		this.noRights = noRights;
	}

	public GroupBean() {

	}

	/**
	 * Create an EmailGroup
	 * @return Returns a String containing [nextPage].xhtml
	 */
	public String create() {
		hasPermission = true;
		System.out.println("in grup create");
		noRights = "";
		boolean ok = emailGroupDAORemote.create(true,emailGroupDTO);
		if (!ok){
			noRights = "You do not have the rights to create an email group!";
			hasPermission = false;
			
		}
		return "addUserToGroup.xhtml";
	}

	public EmailGroupDTO getEmailGroupDTO() {
		return emailGroupDTO;
	}

	public void setEmailGroupDTO(EmailGroupDTO emailGroupDTO) {
		this.emailGroupDTO = emailGroupDTO;
	}
}
